package cn.humaohua.study.elasticsearch6x.controller;

import cn.humaohua.study.elasticsearch6x.util.ElasticsearchUtil;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@EnableAutoConfiguration
@RequestMapping("/es")
public class EsController {
    private static String indexName = "test_index";
    private static String esType = "external";

    public String createIndex(HttpServletRequest request, HttpServletResponse response) {
        if (!ElasticsearchUtil.isIndexExist(indexName)) {
            ElasticsearchUtil.createIndex(indexName);
            return "索引创建成功";
        } else {
            return "索引已经存在";
        }
    }
}
